﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.Xml;
using System.Net;
using System.IO;
using System.Diagnostics;

namespace LinSM
{
    
    class UpDate
    {
        //更新方式
        public bool isUp()
        {
            if (Convert.ToInt32(version()) == 1)
            {
                MessageBox.Show("检测到有新版本");//只提示
                return false;
            }
            if (Convert.ToInt32(version()) == 2)
            {
                MessageBox.Show("当前版本已经不可用");//提示
                Process.Start("UpDate.exe");// 运行更新程序
                Application.Exit();//退出
                return false;
            }
            if (Convert.ToInt32(version()) == 5)
            {
                MessageBox.Show("获取更新信息失败,请尝试更新");
                //Process.Start("UpDate.exe");// 运行更新程序
                return false;
            }
            return true;
        }
        //判断更新
        private string version()
        {
            try
            {
                string strUrl = "http://www.5xiao.com/ver/linsm.txt";
                Uri uri = new Uri(strUrl);
                WebRequest wr = WebRequest.Create(uri);
                Stream s = wr.GetResponse().GetResponseStream();
                StreamReader sr = new StreamReader(s, Encoding.Default);
                string all = sr.ReadToEnd();
                int i = all.IndexOf("[") + 2;//
                string tempver = all.Substring(i, 1);
                string ver = tempver.Replace("]", "").Replace(" ", "");
                return ver;
            }
            catch
            {
                return Convert.ToString(5);
            }
        }
    }
}
